//
//  EAButton.m
//  WhatToEat
//
//  Created by 方力 on 15/7/30.
//  Copyright (c) 2015年 Mac. All rights reserved.
//
#import "Commtools.h"
#import "EAMYButton.h"

@implementation EAMYButton


-(id)init
{
    
    self=[super init];
    
    if (self) {
  
    }
    
    return self;
    
}


-(id)initWithCoder:(NSCoder *)aDecoder
{
    
    self=[super initWithCoder:aDecoder];
    
    if (self) {
        
        
        [self setImage:[UIImage imageNamed:@"wei"] andSetSelctedImage:[UIImage imageNamed:@"xuanzhong"]];
        
       
        [self addTarget:self action:@selector(changeState:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    
    return self;
    
}


-(id)initWithFrame:(CGRect)frame
{
    
    self=[super initWithFrame:frame];
    
    if (self) {
        
    }
    
    return self;
    
}





-(void)setImage:(UIImage *)image andSetSelctedImage:(UIImage * )SelctedImage
{

    
    [self setImage:image forState:0];
    
    
    [self setImage:SelctedImage forState:UIControlStateSelected];
    
    
}

-(void)changeState:(UIButton *)bt
{

    
    bt.selected=!bt.selected;
    
    UITableView * tableView=[Commtools tableView:bt];
   
    for (UITableViewCell * cell in  tableView.visibleCells) {
        
        for (UIView * contentViewSub in cell.contentView.subviews) {
            
            if ([contentViewSub isKindOfClass:[EAMYButton class]]&&![contentViewSub isEqual:bt]) {
                
                EAMYButton * eaBtn=(EAMYButton *)contentViewSub;
                
                eaBtn.selected=NO;
                
                
            }
            
            
            
        }
        
        
        
    }

    





}

@end
